<?php
$articles = $this->articles;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Article manager</title>

<script
	src="<?php echo $this->baseUrl();?>/jquery/jqueryui/jquery-1.6.4.min.js"></script>

<!-- Add sự kiện cho button -->
<script type="text/javascript">
        //Write your code when Document is loaded
        $(document).ready(function() {
        	var hiddenField = document.getElementById('ListCheckboxChecked');

            $("#bPublish").click(function() {
                $("#checklist :checked").each(function() {
                    hiddenField.value += $(this).val()+',';
				});

				$("#myform").attr("action", "manager?todo=publish");
				$("#myform").submit();
			});

            $("#bUnpublish").click(function() {
                $("#checklist :checked").each(function() {
                    hiddenField.value += $(this).val()+',';
				});

				$("#myform").attr("action", "manager?todo=unpublish");
				$("#myform").submit();
			});

            $("#bDelete").click(function() {
            	if(confirm('Do you realy want to delete this article ?'))
            	{
	                $("#checklist :checked").each(function() {
	                    hiddenField.value += $(this).val()+',';
					});
					
					$("#myform").attr("action", "manager?todo=delete");
					$("#myform").submit();
            	}
			});

            $("#bNew").click(function() {
				$("#myform").attr("action", "new");
				$("#myform").submit();
			});

            //Event for check all checkbox
            $('#checkall').click(
         		   function()
         		   {
         		      $("INPUT[type='checkbox']").attr('checked', $('#checkall').is(':checked'));   
         		   }
         		);
       });
    	</script>

</head>
<body>
<h1>Article manager</h1>

<form method="post" id="myform">

<table width="100%">
	<tr align="right">
		<td>
			<input type="button" id="bNew" value="New" /> 
			<input type="button" id="bPublish" value="Publish" /> 
			<input type="button" id="bUnpublish" value="Unpublish" /> 
			<input type="button" id="bDelete" value="Delete" />
		</td>
	</tr>
</table>

<div id="checklist">
<table width="100%" border="1">
	<tr>
		<td><input type="checkbox" id="checkall" name="checkAll"
			value="checkAll"></td>
		<td><b>Title</b></td>
		<td><b>Published</b></td>
		<td><b>Category</b></td>
		<td><b>Created by</b></td>
		<td><b>Date</b></td>
		<td><b>ID</b></td>
	</tr>
	<?php 
	foreach ($articles as $article)
	{
		$ID = $article['ID'];
		echo '<tr>';
		echo 	"<td><input type=\"checkbox\" name=\"$ID\" value=\"$ID\"></td>";
		echo	"<td width=\"300px\"><a href=\"edit?id=$ID\">{$article['Title']}</a></td>";
		echo	"<td>{$article['State']}</td>";
		echo	"<td>{$article['CategoryName']}</td>";
		echo	"<td>{$article['CreatedByName']}</td>";
		echo	"<td>{$article['CreatedTime']}</td>";
		echo	"<td>{$article['ID']}</td>";
		echo '</tr>';
	}
	?>
	
</table>
<input type="hidden" id="ListCheckboxChecked" name="ListCheckboxChecked" />
</div>
</form>
</body>
</html>